<?php
function plugin_render() {
    $result = '';
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        if (isset($_POST['type']) && $_POST['type'] === 'to_date') {
            $ts = trim($_POST['timestamp'] ?? '');
            if (is_numeric($ts)) {
                $result = date('Y-m-d H:i:s', (int)$ts);
            } else {
                $result = '请输入有效的时间戳';
            }
        } elseif (isset($_POST['type']) && $_POST['type'] === 'to_ts') {
            $date = trim($_POST['datetime'] ?? '');
            $ts = strtotime($date);
            if ($ts !== false) {
                $result = $ts;
            } else {
                $result = '请输入有效的日期时间';
            }
        }
    }
    ?>
    <form method="post" class="space-y-4">
        <div>
            <label class="block mb-1 font-medium">时间戳转日期</label>
            <input name="timestamp" type="text" class="border rounded px-2 py-1 w-64" placeholder="如 1700000000">
            <input type="hidden" name="type" value="to_date">
            <button class="ml-2 px-3 py-1 rounded bg-blue-500 text-white" type="submit">转换</button>
        </div>
        <div>
            <label class="block mb-1 font-medium">日期转时间戳</label>
            <input name="datetime" type="text" class="border rounded px-2 py-1 w-64" placeholder="如 2024-01-01 12:00:00">
            <input type="hidden" name="type" value="to_ts">
            <button class="ml-2 px-3 py-1 rounded bg-blue-500 text-white" type="submit">转换</button>
        </div>
    </form>
    <?php if ($result !== ''): ?>
        <div class="mt-4 p-3 bg-blue-50 border border-blue-200 rounded text-blue-700">结果：<?php echo htmlspecialchars($result); ?></div>
    <?php endif; ?>
    <?php
} 